//===----------------------------------------------------------------------===//
//
// This source file is part of the Soto for AWS open source project
//
// Copyright (c) 2017-2024 the Soto project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of Soto project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

// THIS FILE IS AUTOMATICALLY GENERATED by https://github.com/soto-project/soto-codegenerator.
// DO NOT EDIT.

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif
@_exported import SotoCore

/// Service object for interacting with AWS NotificationsContacts service.
///
/// AWS User Notifications Contacts is a service that allows you to create and manage email contacts for AWS User Notifications. The AWS User Notifications Contacts API Reference provides descriptions, API request parameters, and the JSON response for all email contact related API actions.
public struct NotificationsContacts: AWSService {
    // MARK: Member variables

    /// Client used for communication with AWS
    public let client: AWSClient
    /// Service configuration
    public let config: AWSServiceConfig

    // MARK: Initialization

    /// Initialize the NotificationsContacts client
    /// - parameters:
    ///     - client: AWSClient used to process requests
    ///     - partition: AWS partition where service resides, standard (.aws), china (.awscn), government (.awsusgov).
    ///     - endpoint: Custom endpoint URL to use instead of standard AWS servers
    ///     - middleware: Middleware chain used to edit requests before they are sent and responses before they are decoded 
    ///     - timeout: Timeout value for HTTP requests
    ///     - byteBufferAllocator: Allocator for ByteBuffers
    ///     - options: Service options
    public init(
        client: AWSClient,
        partition: AWSPartition = .aws,
        endpoint: String? = nil,
        middleware: AWSMiddlewareProtocol? = nil,
        timeout: TimeAmount? = nil,
        byteBufferAllocator: ByteBufferAllocator = ByteBufferAllocator(),
        options: AWSServiceConfig.Options = []
    ) {
        self.client = client
        self.config = AWSServiceConfig(
            region: nil,
            partition: partition,
            serviceName: "NotificationsContacts",
            serviceIdentifier: "notifications-contacts",
            serviceProtocol: .restjson,
            apiVersion: "2018-05-10",
            endpoint: endpoint,
            serviceEndpoints: Self.serviceEndpoints,
            partitionEndpoints: Self.partitionEndpoints,
            errorType: NotificationsContactsErrorType.self,
            middleware: middleware,
            timeout: timeout,
            byteBufferAllocator: byteBufferAllocator,
            options: options
        )
    }


    /// custom endpoints for regions
    static var serviceEndpoints: [String: String] {[
        "aws-global": "notifications-contacts.us-east-1.api.aws"
    ]}

    /// Default endpoint and region to use for each partition
    static var partitionEndpoints: [AWSPartition: (endpoint: String, region: SotoCore.Region)] {[
        .aws: (endpoint: "aws-global", region: .useast1)
    ]}


    // MARK: API Calls

    /// Activates an email contact using an activation code. This code is in the activation email sent to the email address associated with this email contact.
    @Sendable
    @inlinable
    public func activateEmailContact(_ input: ActivateEmailContactRequest, logger: Logger = AWSClient.loggingDisabled) async throws -> ActivateEmailContactResponse {
        try await self.client.execute(
            operation: "ActivateEmailContact", 
            path: "/emailcontacts/{arn}/activate/{code}", 
            httpMethod: .PUT, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// Activates an email contact using an activation code. This code is in the activation email sent to the email address associated with this email contact.
    ///
    /// Parameters:
    ///   - arn: The Amazon Resource Name (ARN) of the resource.
    ///   - code: The activation code for this email contact. An email contact has a maximum of five activation attempts. Activation codes expire after 12 hours and are generated by the SendActivationCode API action.
    ///   - logger: Logger use during operation
    @inlinable
    public func activateEmailContact(
        arn: String,
        code: String,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> ActivateEmailContactResponse {
        let input = ActivateEmailContactRequest(
            arn: arn, 
            code: code
        )
        return try await self.activateEmailContact(input, logger: logger)
    }

    /// Creates an email contact for the provided email address.
    @Sendable
    @inlinable
    public func createEmailContact(_ input: CreateEmailContactRequest, logger: Logger = AWSClient.loggingDisabled) async throws -> CreateEmailContactResponse {
        try await self.client.execute(
            operation: "CreateEmailContact", 
            path: "/2022-09-19/emailcontacts", 
            httpMethod: .POST, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// Creates an email contact for the provided email address.
    ///
    /// Parameters:
    ///   - emailAddress: The email address this email contact points to. The activation email and any subscribed emails are sent here.  This email address can't receive emails until it's activated.
    ///   - name: The name of the email contact.
    ///   - tags: A map of tags assigned to a resource. A tag is a string-to-string map of key-value pairs.
    ///   - logger: Logger use during operation
    @inlinable
    public func createEmailContact(
        emailAddress: String,
        name: String,
        tags: [String: String]? = nil,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> CreateEmailContactResponse {
        let input = CreateEmailContactRequest(
            emailAddress: emailAddress, 
            name: name, 
            tags: tags
        )
        return try await self.createEmailContact(input, logger: logger)
    }

    /// Deletes an email contact.  Deleting an email contact removes it from all associated notification configurations.
    @Sendable
    @inlinable
    public func deleteEmailContact(_ input: DeleteEmailContactRequest, logger: Logger = AWSClient.loggingDisabled) async throws -> DeleteEmailContactResponse {
        try await self.client.execute(
            operation: "DeleteEmailContact", 
            path: "/emailcontacts/{arn}", 
            httpMethod: .DELETE, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// Deletes an email contact.  Deleting an email contact removes it from all associated notification configurations.
    ///
    /// Parameters:
    ///   - arn: The Amazon Resource Name (ARN) of the resource.
    ///   - logger: Logger use during operation
    @inlinable
    public func deleteEmailContact(
        arn: String,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> DeleteEmailContactResponse {
        let input = DeleteEmailContactRequest(
            arn: arn
        )
        return try await self.deleteEmailContact(input, logger: logger)
    }

    /// Returns an email contact.
    @Sendable
    @inlinable
    public func getEmailContact(_ input: GetEmailContactRequest, logger: Logger = AWSClient.loggingDisabled) async throws -> GetEmailContactResponse {
        try await self.client.execute(
            operation: "GetEmailContact", 
            path: "/emailcontacts/{arn}", 
            httpMethod: .GET, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// Returns an email contact.
    ///
    /// Parameters:
    ///   - arn: The Amazon Resource Name (ARN) of the email contact to get.
    ///   - logger: Logger use during operation
    @inlinable
    public func getEmailContact(
        arn: String,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> GetEmailContactResponse {
        let input = GetEmailContactRequest(
            arn: arn
        )
        return try await self.getEmailContact(input, logger: logger)
    }

    /// Lists all email contacts created under the Account.
    @Sendable
    @inlinable
    public func listEmailContacts(_ input: ListEmailContactsRequest, logger: Logger = AWSClient.loggingDisabled) async throws -> ListEmailContactsResponse {
        try await self.client.execute(
            operation: "ListEmailContacts", 
            path: "/emailcontacts", 
            httpMethod: .GET, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// Lists all email contacts created under the Account.
    ///
    /// Parameters:
    ///   - maxResults: The maximum number of results to include in the response. If more results exist than the specified MaxResults value, a token is included in the response so that the remaining results can be retrieved.
    ///   - nextToken: An optional token returned from a prior request. Use this token for pagination of results from this action. If this parameter is specified, the response includes only results beyond the token, up to the value specified by MaxResults.
    ///   - logger: Logger use during operation
    @inlinable
    public func listEmailContacts(
        maxResults: Int? = nil,
        nextToken: String? = nil,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> ListEmailContactsResponse {
        let input = ListEmailContactsRequest(
            maxResults: maxResults, 
            nextToken: nextToken
        )
        return try await self.listEmailContacts(input, logger: logger)
    }

    /// Lists all of the tags associated with the Amazon Resource Name (ARN) that you specify. The resource can be a user, server, or role.
    @Sendable
    @inlinable
    public func listTagsForResource(_ input: ListTagsForResourceRequest, logger: Logger = AWSClient.loggingDisabled) async throws -> ListTagsForResourceResponse {
        try await self.client.execute(
            operation: "ListTagsForResource", 
            path: "/tags/{arn}", 
            httpMethod: .GET, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// Lists all of the tags associated with the Amazon Resource Name (ARN) that you specify. The resource can be a user, server, or role.
    ///
    /// Parameters:
    ///   - arn: The ARN you specified to list the tags of.
    ///   - logger: Logger use during operation
    @inlinable
    public func listTagsForResource(
        arn: String,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> ListTagsForResourceResponse {
        let input = ListTagsForResourceRequest(
            arn: arn
        )
        return try await self.listTagsForResource(input, logger: logger)
    }

    /// Sends an activation email to the email address associated with the specified email contact.  It might take a few minutes for the activation email to arrive. If it doesn't arrive, check in your spam folder or try sending another activation email.
    @Sendable
    @inlinable
    public func sendActivationCode(_ input: SendActivationCodeRequest, logger: Logger = AWSClient.loggingDisabled) async throws -> SendActivationCodeResponse {
        try await self.client.execute(
            operation: "SendActivationCode", 
            path: "/2022-10-31/emailcontacts/{arn}/activate/send", 
            httpMethod: .POST, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// Sends an activation email to the email address associated with the specified email contact.  It might take a few minutes for the activation email to arrive. If it doesn't arrive, check in your spam folder or try sending another activation email.
    ///
    /// Parameters:
    ///   - arn: The Amazon Resource Name (ARN) of the resource.
    ///   - logger: Logger use during operation
    @inlinable
    public func sendActivationCode(
        arn: String,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> SendActivationCodeResponse {
        let input = SendActivationCodeRequest(
            arn: arn
        )
        return try await self.sendActivationCode(input, logger: logger)
    }

    /// Attaches a key-value pair to a resource, as identified by its Amazon Resource Name (ARN). Taggable resources in AWS User Notifications Contacts include email contacts.
    @Sendable
    @inlinable
    public func tagResource(_ input: TagResourceRequest, logger: Logger = AWSClient.loggingDisabled) async throws -> TagResourceResponse {
        try await self.client.execute(
            operation: "TagResource", 
            path: "/tags/{arn}", 
            httpMethod: .POST, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// Attaches a key-value pair to a resource, as identified by its Amazon Resource Name (ARN). Taggable resources in AWS User Notifications Contacts include email contacts.
    ///
    /// Parameters:
    ///   - arn: The ARN of the configuration.
    ///   - tags: A list of tags to apply to the configuration.
    ///   - logger: Logger use during operation
    @inlinable
    public func tagResource(
        arn: String,
        tags: [String: String],
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> TagResourceResponse {
        let input = TagResourceRequest(
            arn: arn, 
            tags: tags
        )
        return try await self.tagResource(input, logger: logger)
    }

    /// Detaches a key-value pair from a resource, as identified by its Amazon Resource Name (ARN). Taggable resources in AWS User Notifications Contacts include email contacts..
    @Sendable
    @inlinable
    public func untagResource(_ input: UntagResourceRequest, logger: Logger = AWSClient.loggingDisabled) async throws -> UntagResourceResponse {
        try await self.client.execute(
            operation: "UntagResource", 
            path: "/tags/{arn}", 
            httpMethod: .DELETE, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// Detaches a key-value pair from a resource, as identified by its Amazon Resource Name (ARN). Taggable resources in AWS User Notifications Contacts include email contacts..
    ///
    /// Parameters:
    ///   - arn: The value of the resource that will have the tag removed. An Amazon Resource Name (ARN) is an identifier for a specific AWS resource, such as a server, user, or role.
    ///   - tagKeys: Specifies a list of tag keys that you want to remove from the specified resources.
    ///   - logger: Logger use during operation
    @inlinable
    public func untagResource(
        arn: String,
        tagKeys: [String],
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> UntagResourceResponse {
        let input = UntagResourceRequest(
            arn: arn, 
            tagKeys: tagKeys
        )
        return try await self.untagResource(input, logger: logger)
    }
}

extension NotificationsContacts {
    /// Initializer required by `AWSService.with(middlewares:timeout:byteBufferAllocator:options)`. You are not able to use this initializer directly as there are not public
    /// initializers for `AWSServiceConfig.Patch`. Please use `AWSService.with(middlewares:timeout:byteBufferAllocator:options)` instead.
    public init(from: NotificationsContacts, patch: AWSServiceConfig.Patch) {
        self.client = from.client
        self.config = from.config.with(patch: patch)
    }
}

// MARK: Paginators

@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension NotificationsContacts {
    /// Return PaginatorSequence for operation ``listEmailContacts(_:logger:)``.
    ///
    /// - Parameters:
    ///   - input: Input for operation
    ///   - logger: Logger used for logging
    @inlinable
    public func listEmailContactsPaginator(
        _ input: ListEmailContactsRequest,
        logger: Logger = AWSClient.loggingDisabled
    ) -> AWSClient.PaginatorSequence<ListEmailContactsRequest, ListEmailContactsResponse> {
        return .init(
            input: input,
            command: self.listEmailContacts,
            inputKey: \ListEmailContactsRequest.nextToken,
            outputKey: \ListEmailContactsResponse.nextToken,
            logger: logger
        )
    }
    /// Return PaginatorSequence for operation ``listEmailContacts(_:logger:)``.
    ///
    /// - Parameters:
    ///   - maxResults: The maximum number of results to include in the response. If more results exist than the specified MaxResults value, a token is included in the response so that the remaining results can be retrieved.
    ///   - logger: Logger used for logging
    @inlinable
    public func listEmailContactsPaginator(
        maxResults: Int? = nil,
        logger: Logger = AWSClient.loggingDisabled        
    ) -> AWSClient.PaginatorSequence<ListEmailContactsRequest, ListEmailContactsResponse> {
        let input = ListEmailContactsRequest(
            maxResults: maxResults
        )
        return self.listEmailContactsPaginator(input, logger: logger)
    }
}

extension NotificationsContacts.ListEmailContactsRequest: AWSPaginateToken {
    @inlinable
    public func usingPaginationToken(_ token: String) -> NotificationsContacts.ListEmailContactsRequest {
        return .init(
            maxResults: self.maxResults,
            nextToken: token
        )
    }
}
